home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Maplin Electronics Catalogue 2001 Winter
/
Maplins Catalogue Winter 2001.iso
/
JScript
/
checkout.js
< prev
next >
Wrap
Text File
|
2001-03-27
|
9KB
|
245 lines
// Checkout.js JavaScript Development by Burgeonet.com
// ****Begin shopping cart functions.****
// ** global variables for the shopping cart.**
var itemNum = new Array();
var itemDescr = new Array();
var itemCost = new Array();
var itemQty = new Array();
// **Function to parse the cookie and extract the ordered **
// **items from the string. This in turn triggers the **
// **writeCart() function to display the shopping cart. **
function itemsOrdered() {
if (getCookieData("Scart")) {
substr0 = getCookieData("Scart")
cLen = substr0.length
offset0 = substr0.indexOf("@")
counter = substr0.substring(0,offset0)
j = 0
for (i=1; i<=counter; i++) {
offsetq = eval('offset' + j + '');
substrq = eval('substr' + j + '');
eval('ind' + i + ' = offsetq + 1');
eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
eval('offset' + i + ' = substr' + i + '.indexOf("^")');
eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
eval('catInd' + i + ' = item' + i + '.indexOf("`")');
eval('itemCat' + i + ' = item' + i + '.substring(0,catInd' + i + ')');
eval('descrInd' + i + ' = item' + i + '.indexOf("~")');
eval('itemDes' + i + ' = item' + i + '.substring((catInd' + i + ' + 1),descrInd' + i + ')');
eval('priceInd' + i + ' = item' + i + '.indexOf("½")');
eval('itemPr' + i + ' = item' + i + '.substring((descrInd' + i + ' + 2),priceInd' + i + ')');
eval('itemQt' + i + ' = item' + i + '.substring((priceInd' + i + ' + 1),offset' + i + ')');
eval('orderDetail(i,itemCat' + i + ',itemDes' + i + ',itemPr' + i + ',itemQt' + i +')');
j++
}
writecheckout();
}
}
// **Builds an array of the items to load the cart.**
function orderDetail(seq,num,descr,cost,Qty) {
itemNum[seq] = num
itemDescr[seq] = descr
itemCost[seq] = cost
itemQty[seq] = Qty
}
// ** Function to write the shopping cart details **
// ** into the table on the shopping cart page.
function writecheckout() {
var ordFrm = ' <BR> '
ordFrm += ' <FORM METHOD="post"'
ordFrm += ' ACTION="https://catalogue.maplin.co.uk/direct/CDEntry.asp" ID="form1"'
ordFrm += ' NAME="form1" Target="about:blank"> <INPUT TYPE="hidden" NAME="TotalItems" VALUE="' + counter + '"> '
ordFrm += ' <TABLE WIDTH="466" BGCOLOR="#000000" BORDER="1"BORDERCOLOR="#000096"'
ordFrm += ' CELLPADDING="0" CELLSPACING="0"> '
ordFrm += ' <TR> '
ordFrm += ' <TD BGCOLOR="#FFFFFF"> '
ordFrm += ' <TABLE WIDTH="466" BGCOLOR="#000096" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0"> '
ordFrm += ' <TR VALIGN="TOP"> '
ordFrm += ' <TD WIDTH="60" VALIGN="TOP" ALIGN="LEFT"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF">'
ordFrm += ' <B> Order<BR> Code</B></FONT></TD> '
ordFrm += ' <TD WIDTH="140" VALIGN="TOP" ALIGN="LEFT"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="1"'
ordFrm += ' COLOR="#FFFFFF"><B>Description</B></FONT></TD> '
ordFrm += ' <TD COLSPAN="2" WIDTH="60" VALIGN="TOP" ALIGN="CENTER"><FONT'
ordFrm += ' COLOR="#FFFFFF" FACE="verdana,Arial,helvetica" SIZE="1"><B>Qty</B></FONT></TD> '
ordFrm += ' <TD WIDTH="70" VALIGN="TOP" ALIGN="RIGHT"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF"><B>inc.VAT'
ordFrm += ' <BR>each</B></FONT></TD> '
ordFrm += ' <TD WIDTH="60" ALIGN="RIGHT" VALIGN="TOP"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="-2"'
ordFrm += ' COLOR="#FFFFFF"><B>Total</B></FONT></TD> '
ordFrm += ' <TD VALIGN="TOP" ALIGN="CENTER" WIDTH="80"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="1"'
ordFrm += ' COLOR="#FFFFFF"><B>Remove</B></FONT></TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE> '
ordFrm += ' <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0" BGCOLOR="#FBCE82"> '
ordFrm += ' <TR> '
ordFrm += ' <TD></TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE> '
for (i = 1; i <= counter; i++) {
ordFrm += ' <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0"> '
ordFrm += ' <TR> '
ordFrm += ' <TD WIDTH="60"><FONT FACE="verdana,Arial,helvetica" SIZE="-2"'
ordFrm += ' COLOR="#330099"><B> ' + itemNum[i] + '</B></FONT></TD> '
ordFrm += ' <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2">' + itemDescr[i] + '</FONT></TD> '
ordFrm += ' <TD WIDTH="45" ALIGN="CENTER"><FONT'
ordFrm += ' FACE="verdana,Arial,helvetica" SIZE="1">' + itemQty[i] + '</FONT></TD> '
ordFrm += ' <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2">£' + itemCost[i] + '</FONT></TD> '
ordFrm += ' <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2">£' + fix(itemCost[i] * itemQty[i]) + '</FONT></TD> '
ordFrm += ' <TD WIDTH="80" ALIGN="RIGHT"><A href="javascript:clearIt('+i+')"><IMG'
ordFrm += ' SRC="remove.gif" WIDTH="60" HEIGHT="15" BORDER="0"></A></TD> '
ordFrm += ' <!-- Hidden Text Boxes to store code and quantity for submission -->'
ordFrm += ' <TR> '
ordFrm += ' <TD><INPUT TYPE="hidden" NAME="OrderCode' + i + '" MAXLENGTH="5" VALUE="' + itemNum[i] + '">'
ordFrm += ' <INPUT TYPE="hidden" NAME="Quantity' + i + '" MAXLENGTH="5" VALUE="' + itemQty[i] + '"> </TD> '
ordFrm += ' </TR> '
ordFrm += ' <!-- =========================================================== -->'
ordFrm += ' </TR> '
ordFrm += ' </TABLE> '
ordFrm += ' <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0" BGCOLOR="#FBCE82"> '
ordFrm += ' <TR> '
ordFrm += ' <TD></TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE> '
}
ordFrm += ' <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0"> '
ordFrm += ' <TR> '
ordFrm += ' <TD WIDTH="60"> </TD> '
ordFrm += ' <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2" COLOR="#006400">Total Items = ' + counter + '</FONT></TD> '
ordFrm += ' <TD WIDTH="45" ALIGN="CENTER"> </TD> '
ordFrm += ' <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2" COLOR="#000066">Sub Total</FONT></TD> '
ordFrm += ' <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
ordFrm += ' SIZE="-2">£' + update() + '</FONT></TD> '
ordFrm += ' <TD WIDTH="80" ALIGN="RIGHT"> </TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE>'
ordFrm += ' <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0" BGCOLOR="#FBCE82"> '
ordFrm += ' <TR> '
ordFrm += ' <TD></TD> '
ordFrm += ' </TABLE> '
ordFrm += ' <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
ordFrm += ' CELLSPACING="0"> '
ordFrm += ' <TR VALIGN="MIDDLE"> '
ordFrm += ' <TD ALIGN="LEFT" VALIGN="MIDDLE" WIDTH="192"><A'
ordFrm += ' HREF="javascript:history.go(-1)"><IMG SRC="return.gif" WIDTH="60" HEIGHT="15"'
ordFrm += ' BORDER="0"></A></TD> '
ordFrm += ' <TD ALIGN="CENTER" VALIGN="MIDDLE" WIDTH="82"> </TD> '
ordFrm += ' <TD ALIGN="RIGHT" VALIGN="MIDDLE" WIDTH="192">'
ordFrm += ' <INPUT TYPE="image" SRC="orderbtn.gif" Border="0"></TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE> </TD> '
ordFrm += ' </TR> '
ordFrm += ' </TABLE>'
ordFrm += '</form> '
document.write(ordFrm);
document.close();
}
// ** Function to delete a line item upon user request. **
function clearIt(num) {
itemNum[num] = "item"
rewriteCookie(num)
}
// **Function to rewrite the cookie when the user **
// **deletes a line item from the shopping cart. **
function rewriteCookie(num) {
dataUpdate = ""
for (i=1; i<=counter; i++) {
if (itemNum[i] != "item") {
dataUpdate += itemNum[i] + '`' + itemDescr[i] + '~$' + itemCost[i] + '½' + itemQty[i] + '^'
}
}
counter = counter - 2
cookData = dataUpdate
setCookieData("Scart", cookData, expdate.toGMTString())
history.go(0)
}
// ****End shopping cart detail section.****
// ****Start of code section to display subtotal.****
function update() {
if (getCookieData("Scart")) {
var sub_total = 0;
for (i=1; i<itemNum.length; i++)
eval('sub_total += parseFloat(itemCost[' + i + '] * itemQty[' + i + ']);');
//document.shopCart.subtotal.value= fix(sub_total);
return + fix(sub_total);
}
}
function fix(num) {
string = "" + num;
if (string.indexOf('.') == -1)
return string + '.00';
seperation = string.length - string.indexOf('.');
if (seperation > 3)
return string.substring(0,string.length-seperation+3);
else if (seperation == 2)
return string + '0';
return string;
}
// **Function to clear the shopping cart.**
function killCart() {
killCookie("Scart")
history.go(-1)
}